import Vue from 'vue'
import VueRouter from 'vue-router'
import IndexView from '../views/IndexView.vue'
import TestView from '../views/TestView.vue'
import Article from '../components/CardList.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'test',
    component: TestView,
    redirect:{name:"index"},
    children: [{
      path: "/article/:id",
      name: 'article',
      component: Article,
    },
    {
      path: "/index",
      name: 'index',
      component: IndexView
      },
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  routes
})
router.beforeEach((to, from, next) =>{
  // 获取新的路由参数
  // const newParam = to.params.param1;

  // 根据新的路由参数执行刷新操作，例如重新加载数据等

  // 调用 next() 继续路由切换
  // this.$router.go();
  next();
})

export default router
